import { _decorator, Component, Node, Sprite, Color, ProgressBar } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('ProgressBarController')
export class ProgressBarController extends Component {

    progressBar: ProgressBar = null!;
    progressBarSp: Sprite = null!;

    value: number = 1;

    start() {
        this.progressBar = this.node.getChildByName("ProgressBar").getComponent(ProgressBar);
        this.progressBarSp = this.node.getChildByName("ProgressBar").getComponent(Sprite);
    }

    Progress(value: number) {
        if (value >= 0.3) {
            this.progressBarSp.color = new Color(58, 197, 105, 255);//绿色
        } else if (value >= 0.15 && value < 0.4) {
            this.progressBarSp.color = new Color(248, 202, 0, 255);//黄色
        } else {
            this.progressBarSp.color = new Color(255, 78, 80, 255);//红色
        }

        this.progressBar.progress = value;
    }

}


